import time
import insertion_sort_generator
import insertion_sort

def is_sorted(arr):
    return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1))

def run_test(test_name, data):
    print(f"=== 测试：{test_name} ===")
    data_copy = data.copy()
    start_time = time.time()
    sorted_data = insertion_sort.insertion_sort(data_copy)
    end_time = time.time()

    correct = is_sorted(sorted_data)
    runtime = end_time - start_time

    print(f"正确性: {'✔️' if correct else '❌'}")
    print(f"运行时间: {runtime:.6f} 秒")
    print()

def main():
    sizes = [10, 100, 1000]

    for size in sizes:
        random_data = insertion_sort_generator.generate_random_list(size)
        sorted_data = insertion_sort_generator.generate_sorted_list(size)
        reversed_data = insertion_sort_generator.generate_reversed_list(size)

        run_test(f"随机数组（{size}个元素）", random_data)
        run_test(f"升序数组（{size}个元素）", sorted_data)
        run_test(f"降序数组（{size}个元素）", reversed_data)

if __name__ == "__main__":
    main()
